home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / tutor / pro10 / inandout.bas < prev    next >
Encoding:
BASIC Source File  |  1990-07-27  |  2.0 KB  |  47 lines

  1. 10 'INANDOUT.BAS - program to illustrate the use of input and output using
  2. 20 'disk and printer devices
  3. 30 'Program written by Richard Harper and modified by (Your name here!)
  4. 40 'From the GW-BASIC tutorial series, file GWBT03  08/15/1990
  5. 50 '
  6. 60 'For this demonstration, we will be using the following variables and
  7. 70 'devices:
  8. 80 '     TEXTFILE.TXT           is our disk file
  9. 90 '     LINEOFDATA$            is the string variable that we will use
  10. 100 '                           for input and output
  11. 110 '    LPT1:                  is the printer.  Please note that if your
  12. 120 '                           printer is attached to the second parallel
  13. 130 '                           port (LPT2:), you will need to change all of
  14. 140 '                           the LPT1: device names to LPT2:
  15. 150 '
  16. 160 'If you have no printer, change the LPT1: device name to SCRN: instead
  17. 170 'so that all lines will print on your screen.
  18. 180 'Start of main program:
  19. 190 CLS
  20. 200 PRINT "We are going to demonstrate use of disk files and printer input
  21. 210 PRINT "and output.  Please type in several lines, pressing ENTER at"
  22. 220 PRINT "the end of each line, and press ENTER alone on a new line to quit"
  23. 230 PRINT "entering lines and to see the remainer of the demonstration."
  24. 240 PRINT
  25. 250 'This next line opens the TEXTFILE.TXT file
  26. 260 OPEN "TEXTFILE.TXT" FOR OUTPUT AS #1
  27. 270 LINE INPUT "Enter a line: ",LINEOFDATA$
  28. 280 IF LINEOFDATA$="" THEN GOTO 320
  29. 290 PRINT #1,LINEOFDATA$
  30. 300 GOTO 270
  31. 310 'The user has entered a blank line, so let's show what we have in the file
  32. 320 PRINT #1,LINEOFDATA$
  33. 330 CLOSE #1
  34. 340 'Notice that we CLOSE the file when we are done, so it can be used for
  35. 350 'INPUT below, and also so we can use the #1 device handle again
  36. 360 OPEN "TEXTFILE.TXT" FOR INPUT AS #1
  37. 370 OPEN "LPT1:" FOR OUTPUT AS #2
  38. 380 LINE INPUT #1,LINEOFDATA$
  39. 390 IF LINEOFDATA$="" THEN GOTO 430
  40. 400 PRINT #2,LINEOFDATA$
  41. 410 GOTO 380
  42. 420 'All done, so close all devices and end the program
  43. 430 CLOSE #1
  44. 440 CLOSE #2
  45. 450 END
  46. 460 'End of program - INANDOUT.BAS
  47.